<?php

/**
 * ContactForm class.
 * ContactForm is the data structure for keeping
 * contact form data. It is used by the 'contact' action of 'SiteController'.
 */
class AnswerForm extends CFormModel
{
	public $avatar;
	public $email;
	public $content;
	public $ask_id;
	public $verifyCode;

	/**
	 * Declares the validation rules.
	 */
	public function rules()
	{
		return array(
			// name, email, subject and body are required
			array('avatar, email, content, ask_id', 'required'),
			// email has to be a valid email address
			array('email', 'email'),
			// verifyCode needs to be entered correctly
			array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
		);
	}

	/**
	 * Declares customized attribute labels.
	 * If not declared here, an attribute would have a label that is
	 * the same as its name with the first letter in upper case.
	 */
	public function attributeLabels()
	{
		return array(
			'verifyCode'=>Yii::t('main','Verification Code'),
			'avatar'=>Yii::t('main','Full name'),
			'content'=>Yii::t('main','Content')
		);
	}
	public function save()
	{
		$model = new FrontendAnswersModel();
		$model->attributes = $this->attributes;
		$model->updated_datetime = date('Y-m-d H:i:s');
		$model->published = 1;
		return $model->save();
	}
}